package o;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.RemoteException;
import android.text.TextUtils;
import com.huawei.appmarket.framework.coreservice.BaseIPCRequest;
import com.huawei.appmarket.framework.coreservice.DataHolder;
import com.huawei.appmarket.framework.coreservice.Status;
import com.huawei.appmarket.service.externalapi.secureactivity.SecureProxyActivity;
import com.huawei.appmarket.service.externalservice.distribution.download.request.BatchDownloadIPCRequest;
import com.huawei.appmarket.service.externalservice.distribution.download.request.DownloadInfo;
import com.huawei.appmarket.service.externalservice.distribution.download.request.StartDownloadIPCRequest;
import com.huawei.appmarket.service.externalservice.distribution.download.request.StartDownloadV2IPCRequest;
import com.huawei.appmarket.service.thirdappdl.ThirdAppDownloadActivityProtocol;
import com.huawei.appmarket.service.thirdappdl.ThirdAppDownloadActivityProtocol.Request;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import o.dhh.b;

public class dhc extends b {
    private static final Map<String, Class<? extends dhe>> ॱ = new ConcurrentHashMap();
    private Context ˏ;

    static {
        ˋ("method.cancelTask", dzb.class);
        ˋ("method.pauseTask", dza.class);
        ˋ("method.queryTasks", dzc.class);
        ˋ("method.resumeTask", dzi.class);
        ˋ("method.startDownloadTask", dzj.class);
        ˋ("method.registerDownloadCallback", dze.class);
        ˋ("method.unregisterDownloadCallback", dzf.class);
        ˋ("method.unregisterDownloadCallback", dzf.class);
        ˋ("method.batchDownloadTask", dyy.class);
        ˋ("method.startDownloadTaskV2", dzh.class);
        ˋ("method.getInstallReferred", dzk.class);
    }

    public static void ˋ(String str, Class<? extends dhe> cls) {
        ॱ.put(str, cls);
    }

    public void ˊ(Context context) {
        this.ˏ = context;
    }

    public void ˊ(DataHolder dataHolder, dgz o_dgz) throws RemoteException {
        if (dataHolder == null || TextUtils.isEmpty(dataHolder.ˎ()) || dataHolder.ˏ() == null) {
            Logger.ˎ("AGTransportBinder", "asyncCall error param");
            o_dgz.ॱ(new Status(9));
            return;
        }
        Logger.ˎ("AGTransportBinder", "asyncCall:" + dataHolder.ˎ());
        String[] packagesForUid = this.ˏ.getPackageManager().getPackagesForUid(getCallingUid());
        if (packagesForUid == null) {
            Logger.ˎ("AGTransportBinder", "asyncCall invalid uid");
            o_dgz.ॱ(new Status(9));
        } else if (cgp.ˎ(packagesForUid, dataHolder.ˏ().ˏ())) {
            ॱ(dataHolder, packagesForUid);
            if (!diu.ˊ().ˎ()) {
                Logger.ˎ("AGTransportBinder", "protocol error");
                Status status = new Status(15);
                Intent intent = new Intent("com.huawei.appmarket.intent.action.PROTOCOL");
                intent.putExtra("view_type", 1);
                intent.putExtra("source", "AGTransport");
                BaseIPCRequest ˊ = dataHolder.ˊ();
                intent.putExtra("method", dataHolder.ˎ());
                intent.putExtra("mediaPkg", dataHolder.ˏ().ˋ());
                ˊ(intent, ˊ);
                intent.setPackage(this.ˏ.getPackageName());
                status.ˊ(SecureProxyActivity.ˎ(this.ˏ, dataHolder.ˏ().ˋ(), intent));
                o_dgz.ॱ(status);
            } else if (!ॱ(dataHolder, o_dgz)) {
                Class cls = (Class) ॱ.get(dataHolder.ˎ());
                if (cls == null) {
                    Logger.ˎ("AGTransportBinder", "asyncCall unsupport method");
                    o_dgz.ॱ(new Status(5));
                } else if (dataHolder.ˊ() == null) {
                    Logger.ˎ("AGTransportBinder", "asyncCall unsupport method, can not get the request");
                    o_dgz.ॱ(new Status(5));
                } else {
                    try {
                        ((dhe) cls.newInstance()).ˊ(this.ˏ, dataHolder, o_dgz);
                    } catch (Throwable e) {
                        Logger.ˋ("AGTransportBinder", "instance failed ", e);
                        o_dgz.ॱ(new Status(5));
                    } catch (Throwable e2) {
                        Logger.ˋ("AGTransportBinder", "instance failed ", e2);
                        o_dgz.ॱ(new Status(5));
                    }
                }
            }
        } else {
            Logger.ˎ("AGTransportBinder", "asyncCall invalid packageName");
            o_dgz.ॱ(new Status(9));
        }
    }

    private void ˊ(Intent intent, BaseIPCRequest baseIPCRequest) {
        if (baseIPCRequest instanceof StartDownloadIPCRequest) {
            intent.putExtra("advPlatform", ((StartDownloadIPCRequest) baseIPCRequest).ˋ());
            intent.putExtra("advInfo", ((StartDownloadIPCRequest) baseIPCRequest).ˏ());
            intent.putExtra("referrer", ((StartDownloadIPCRequest) baseIPCRequest).ॱॱ());
        } else if (baseIPCRequest instanceof StartDownloadV2IPCRequest) {
            intent.putExtra("advPlatform", ((StartDownloadV2IPCRequest) baseIPCRequest).ˋ());
            intent.putExtra("advInfo", ((StartDownloadV2IPCRequest) baseIPCRequest).ˊ());
            intent.putExtra("referrer", ((StartDownloadV2IPCRequest) baseIPCRequest).ᐝ());
        } else if (baseIPCRequest instanceof BatchDownloadIPCRequest) {
            intent.putExtra("advPlatform", ((BatchDownloadIPCRequest) baseIPCRequest).ˋ());
            List ˏ = ((BatchDownloadIPCRequest) baseIPCRequest).ˏ();
            if (ˏ.size() != 0) {
                intent.putExtra("advInfo", ((DownloadInfo) ˏ.get(0)).ˋ());
                intent.putExtra("referrer", ((DownloadInfo) ˏ.get(0)).ˏ());
            }
        }
    }

    private boolean ॱ(DataHolder dataHolder, dgz o_dgz) throws RemoteException {
        int ॱ = dataHolder.ˏ().ॱ();
        PackageInfo packageInfo = null;
        try {
            packageInfo = this.ˏ.getPackageManager().getPackageInfo(this.ˏ.getPackageName(), 0);
        } catch (NameNotFoundException e) {
            Logger.e("AGTransportBinder", "can not find pkg");
        }
        if (packageInfo == null || packageInfo.versionCode >= ॱ) {
            return false;
        }
        Logger.ˎ("AGTransportBinder", "requireVersionCode: " + ॱ + ", LocalVersion: " + packageInfo.versionCode);
        Status status = new Status(2);
        cjo thirdAppDownloadActivityProtocol = new ThirdAppDownloadActivityProtocol();
        Request request = new Request();
        request.ˊ(packageInfo.versionCode);
        request.ˋ(ॱ);
        request.ˋ(dataHolder.ˎ());
        thirdAppDownloadActivityProtocol.ˊ(request);
        status.ˊ(SecureProxyActivity.ˎ(this.ˏ, dataHolder.ˏ().ˋ(), new cjm("update.appgallery.activity", thirdAppDownloadActivityProtocol)));
        o_dgz.ॱ(status);
        return true;
    }

    private void ॱ(DataHolder dataHolder, String[] strArr) {
        if (TextUtils.isEmpty(dataHolder.ˏ().ˋ())) {
            dataHolder.ˏ().ˎ(dataHolder.ˏ().ˏ());
            return;
        }
        Object obj;
        for (String str : dhd.ˏ()) {
            if (cgp.ˎ(strArr, str)) {
                try {
                    PackageInfo packageInfo = this.ˏ.getPackageManager().getPackageInfo(str, 64);
                    if (!(packageInfo == null || packageInfo.signatures == null || packageInfo.signatures.length <= 0)) {
                        Object ॱ = eux.ॱ(dnk.ˏ(doa.ˊ(packageInfo.signatures[0].toCharsString())));
                        if (!TextUtils.isEmpty(ॱ) && dhd.ˊ(str, ॱ.toLowerCase(Locale.ENGLISH))) {
                            obj = 1;
                            break;
                        }
                    }
                } catch (NameNotFoundException e) {
                    Logger.e("AGTransportBinder", "can not find pkg:" + str);
                }
            }
        }
        obj = null;
        if (obj == null) {
            dataHolder.ˏ().ˎ(dataHolder.ˏ().ˏ());
        }
    }
}
